import request from '@/utils/request'; 
import { da } from 'element-plus/es/locales.mjs'; 
import { jwtDecode } from 'jwt-decode'; 

// 添加健康指标接口
export function addIndicator(data) {
    return request({
        url: '/health/addIndicator',
        method: 'post',
        data: data
    }).then(response => {
        console.log('addIndicator 接口响应:', response);
        if (response.code !== "000") {
            console.error('addIndicator 调用失败:', response.data);
            throw new Error(`000 ${response.msg.error}`);
        }
        return response;
    }).catch(error => {
        console.error('addIndicator 请求失败:', error);
        throw error;
    });
}

// 删除健康指标接口
export function deleteIndicator(data) {
    return request({
        url: '/health/deleteIndicator',
        method: 'delete',
        data: data
    }).then(response => {
        console.log('deleteIndicator 接口响应:', response);
        if (response.code === "000") {
            return response;
            
        }
        console.error('deleteIndicator 调用失败:', response.statusText);
            throw new Error(`000 Method Not Allowed`);
    }).catch(error => {
        console.error('deleteIndicator 请求失败:', error);
        throw error;
    });
}

// 更新健康指标接口
export function updateIndicator(data) {
    return request({
        url: '/health/updateIndicator',
        method: 'put',
        data: data
    }).then(response => {
        console.log('updateIndicator 接口响应:', response);
        if (response.code === "000") {
            return response;
        } else {
            console.error('updateIndicator 调用失败:', response.statusText);
            throw new Error(`非 000 状态码: ${response.status}`);
        }
    }).catch(error => {
        console.error('updateIndicator 请求失败:', error);
        throw error;
    });
}

// 查询健康指标接口
export function queryIndicator(data) {
    return request({
        url: '/health/queryIndicator',
        method: 'post',
        data: data
    }).then(response => {
        console.log('queryIndicator 接口响应:', response);
        if (response.code === "000") {
            return response;
        } else {
            console.error('queryIndicator 调用失败:', response.statusText);
            throw new Error(`非 000 状态码: ${response.status}`);
        }
    }).catch(error => {
        console.error('queryIndicator 请求失败:', error);
        throw error;
    });
}